﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.DomainObjects;
using System.Data.SqlClient;
using System.Data;
using BestLifePOS_Core.Exceptions.DataBase;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeGetAllSTNByStatusDataAction : BestLifeDataAction<List<STN>>
    {
         private string GvStatus;
         public BestLifeGetAllSTNByStatusDataAction(string PStatus)
        {
            GvStatus = PStatus;
        }

        public override List<STN> Body(SqlConnection PConn)
        {
            try
            {
                List<STN> LvList = new List<STN>();

                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.GetSTNDetailsByStatus";
                LvCommand.Parameters.Add(new SqlParameter("@Status", GvStatus));
           
                SqlDataReader LvReader = LvCommand.ExecuteReader();
                while (LvReader.Read())
                {
                    STN LvSTN = new STN();
                    LvSTN.STN_Id = LvReader.GetValue(0).ToString();
                    LvSTN.Branch_Id = LvReader.GetValue(0).ToString();
                    LvSTN.status = LvReader.GetValue(0).ToString();
                    //LvSTN.Issue_Date = LvReader.GetValue(0).ToString();
                    //LvSTN.Total = LvReader.GetValue(0).ToString();
                    LvSTN.User_Id = LvReader.GetValue(0).ToString();
                    //LvSTN.Date_Create = LvReader.GetValue(0).ToString();

                    LvList.Add(LvSTN);
                }


                return LvList;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
